from flask import Blueprint,render_template,request,session
from .forms import RegistForm,LoginFrom
from .models import FrontUser

from utils import restful_result,restful
from exts import db
bp = Blueprint('front',__name__)

@bp.route('/')
def index():
    return render_template('front/index.html')

@bp.route('/animation/',methods=["GET","POST"])
def animation():
    if request.method == "GET":
        return render_template('front/animation.html')

@bp.route('/search/',methods=["GET","POST"])
def search():
    if request.method == "GET":
        return render_template('front/search.html')

@bp.route('/login/',methods=["GET","POST"])
def login():
    if request.method=="GET":
        return render_template('front/login.html')

@bp.route('/regist/',methods=['GET',"POST"])
def regist():
    if request.method == "GET":
        return render_template('front/register.html')
    else:
        form = RegistForm(request.form)
        if form.validate():
            contact = form.name.data
            telephone = form.telephone.data
            email = form.telephone.data
            password = form.password.data

            user = FrontUser(name=contact,email=email,password=password)
            db.session.add(user)
            db.session.commit()
            return restful.success()
        else:
            return restful.params_error(form.get_error())